package file

import (
	"gitee.com/binny_w/gin_starter/core"
	"github.com/gin-gonic/gin"
	"net/http"
	"time"
)

func get(c *gin.Context) {
	bucket := c.DefaultQuery("bucket", core.DefaultBucket)
	key := c.Query("key")
	url, err := core.Storage.GetObjectSignedUrl(c, bucket, key, 7*24*time.Hour, core.RedisCache)
	if err != nil {
		_ = c.AbortWithError(500, err)
		return
	}
	if url == "" {
		c.AbortWithStatus(http.StatusNotFound)
		return
	}
	c.Redirect(http.StatusFound, url)
}
